package ir.values;

import frontend.visitor.symboltbl.scope.Scope;
import ir.types.LabelType;
import ir.values.users.instructions.Instruction;

import java.util.LinkedList;

public class BasicBlock extends Value {
    private final LinkedList<Instruction> instructions = new LinkedList<>();
    public BasicBlock() {
        super(null, new LabelType());
    }
    @Override
    public String parseUsingName() {
        return "%" + id;
    }
    public String parseLLVM() {
        StringBuilder sb = new StringBuilder();
        sb
                .append(id)
                .append(":\n");
        for (int i = 0; i < instructions.size(); i++) {
            Instruction instruction = instructions.get(i);
            sb.append("    ").append(instruction.parseLLVM());
            if (i != instructions.size() - 1) {
                sb.append("\n");
            }
        }
        return sb.toString();
    }

    public void addInstruction(Instruction instruction) {
        instructions.add(instruction);
    }

    public LinkedList<Instruction> getInstructions() {
        return instructions;
    }
}
